package com.xiaobai.zhuangxiuguanjia.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.xiaobai.zhuangxiuguanjia.R;

public class SplashActivity extends Activity implements Runnable {

    private ImageView img1;
    private ImageView img3;
    private Animation animation2;
    private Animation animation1;

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            img1.setImageResource(msg.arg2);
            img3.setImageResource(msg.arg1);
            img3.startAnimation(animation2);
            img1.startAnimation(animation1);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_splash);

        img1 = (ImageView) findViewById(R.id.splash_img1);
        img3 = (ImageView) findViewById(R.id.splash_img3);

        animation1 = AnimationUtils.loadAnimation(this, R.anim.anim1_splash);
        animation2 = AnimationUtils.loadAnimation(this, R.anim.anim2_splash);

        new Thread(this).start();
    }

    @Override
    public void run() {
        try {
            Thread.sleep(800);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        Message message = Message.obtain();
        message.arg1 = R.mipmap.icon_lunch_top_last;
        message.arg2 = R.mipmap.lunch;
        handler.sendMessage(message);

        try {
            Thread.sleep(1500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        startActivity(new Intent(this, MainActivity.class));
        this.finish();
    }
}
